#include "Utils.h"
#include <sys/types.h>
#include <sys/mman.h>

using namespace llvm;
using namespace std;

void CopyInstructions(BasicBlock *BB, vector<Instruction*> &Instructions)
{
	for (BasicBlock::iterator BBI = BB->begin(), BBE = BB->end(); BBI != BBE; ++BBI)
		Instructions.push_back(&*BBI);
}

void CopyInstructions(Function *F, vector<Instruction*> &Instructions)
{
	for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
		CopyInstructions(&*FI, Instructions);
}

void CopyInstructions(Module *M, vector<Instruction*> &Instructions)
{
	for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
		CopyInstructions(&*MI, Instructions);
}

int isCached(void *addr)
{
	char c;
	mincore((void*) ((unsigned long) addr & ~4095), 4096, &c);
	return c & 1;
}
